package cn.devcoder.cloudcode.hibernatedao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import cn.devcoder.cloudcode.bean.UserBean;
import cn.devcoder.cloudcode.dao.UserDao;
import cn.devcoder.cloudcode.model.User;


public class HibernateUserDao implements UserDao {
	@Autowired
	private SessionFactory sessionFactory;
	
	public Integer save(UserBean userBean) {
		User user = new User();
		BeanUtils.copyProperties(userBean, user);
		
        Session session = sessionFactory.getCurrentSession();  
          
		Integer id =  (Integer) session.save(user);  
          
		return id;
	}
}
